package edu.ucsd.cse135.gas.action.applicant;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import edu.ucsd.cse135.gas.bean.applicant.AddressForm;
import edu.ucsd.cse135.gas.logic.Degree;
import edu.ucsd.cse135.gas.logic.applicant.Applicant;
import edu.ucsd.cse135.gas.resources.Constants;

public class AddressAction extends Action {

	public AddressAction() {
		super();
	}
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		
		AddressForm addressForm = (AddressForm)form;
		
		Applicant applicant = (Applicant)request.getSession().getAttribute("applicant");
		
		applicant.setStreet(addressForm.getStreet());
		applicant.setCity(addressForm.getCity());
		if(applicant.getUsResidence())
		{
			applicant.setState(addressForm.getState());
		}
		else
		{
			applicant.setCountryPhoneCode(addressForm.getCountryPhoneCode());
		}
		applicant.setZip(addressForm.getZip());
		applicant.setAreaCode(addressForm.getAreaCode());
		applicant.setNumber(addressForm.getNumber());
		
		request.getSession().setAttribute("applicant", applicant);
	
		ArrayList<Degree> degreeList = new ArrayList<Degree>();
		request.getSession().setAttribute("degrees", degreeList);
		
		if(applicant.getUsResidence())
		{
			return mapping.findForward(Constants.DOMESTIC);
		}
		else
		{
			return mapping.findForward(Constants.NOT_DOMESTIC);
		}
	}
	
}
